package com.zijidelu.luframework.config.thread;

import com.zijidelu.luframework.utils.concurrent.ThreadPoolUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * 线程池配置类。
 *
 * @author ZIJIDELU
 * @datetime 2025/10/30 12:27
 */
@Slf4j
@Configuration
public class ThreadPoolConfig {

    @Bean("domainEventExecutor")
    public Executor domainEventExecutor() {
        final ThreadPoolTaskExecutor executor = ThreadPoolUtil.calcThreadPoolSize(true, new ThreadPoolTaskExecutor());
        // 线程前缀名
        executor.setThreadNamePrefix("domain-event-");
        // 初始化
        executor.initialize();

        log.info("[DomainEventExecutor] => STATUS: RUNNING | Core={} | Max={} | Queue={}",
                executor.getCorePoolSize(), executor.getMaxPoolSize(), executor.getQueueCapacity());

        return executor;
    }

}
